<template>
  <v-layout type="main">
    <el-form class="form" ref="form" :model="addForm" label-width="124px">
      <el-form-item label="GPU" prop="gpu_model_mem">
        <el-input type="text" v-model="addForm.gpu_num">
          <template slot="append">
            <div class="short-append">个</div>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="CPU" prop="cpu_num">
        <el-input type="text" v-model="addForm.cpu_num">
          <template slot="append">
            <div class="short-append">毫核</div>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="内存" prop="mem_num">
        <el-input type="text" v-model="addForm.mem_num">
          <template slot="append">
            <div class="short-append">Mi</div>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="网络RDMA" prop="rdma_num">
        <el-input type="text" v-model="addForm.rdma_num">
          <template slot="append">
            <div class="short-append">个</div>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label=" ">
        <el-button class="none-type" @click="submit">确定</el-button>
      </el-form-item>
    </el-form>
  </v-layout>
</template>

<script>
import { organizationConfigurationDetail, putOrganizationConfiguration } from '@/api/org'
export default {
  data() {
    return {
      detail: null,
      addForm: {
        gpu_num: 0,
        cpu_num: 0,
        mem_num: 0,
        rdma_num: 0,
      },
    };
  },
  async created() {
    this.getData()
  },
  methods: {
    async getData() {
      if (this.$route.query.id) {
        let res = await organizationConfigurationDetail({ id: this.$route.query.id })
        console.log(res.data)
        this.detail = res.data;
        this.addForm.gpu_num = this.detail.gpu_num;
        this.addForm.cpu_num = this.detail.cpu_num;
        this.addForm.mem_num = this.detail.mem_num;
        this.addForm.rdma_num = this.detail.rdma_num;
      }
    },
    submit() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          this.detail.gpu_num = this.addForm.gpu_num
          this.detail.cpu_num = this.addForm.cpu_num
          this.detail.mem_num = this.addForm.mem_num
          this.detail.rdma_num = this.addForm.rdma_num
          await putOrganizationConfiguration({ ...this.detail })
          this.$router.push({
            path: '/orgConfig'
          })
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.form {
  padding: 20px 40px 0 0;
}
</style>